package com.yanqu.road.server.manger.activity.daomu;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.daomu.DaoMuAttribute;
import com.yanqu.road.entity.activity.daomu.DaoMuBattlePropItem;
import com.yanqu.road.entity.activity.daomu.DaoMuReward;
import com.yanqu.road.entity.activity.daomu.DaoMuSkill;
import com.yanqu.road.entity.activity.daomu.config.*;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuNpcStatusEnum;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuSyncConfigTypeEnum;
import com.yanqu.road.entity.activity.daomu.param.DaoMuAttReportRes;
import com.yanqu.road.entity.activity.daomu.param.DaoMuCreateNpcRes;
import com.yanqu.road.entity.activity.daomu.param.DaoMuOpenBoxRes;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGoodsType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.logic.bussiness.activity.DaoMuActivityBusiness;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DaoMuProto;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.daomu.DaoMuActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.festivalgift.FestivalGiftModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.TempCommonMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.daomu.pb.DaoMuActivityPb;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.ListHelper;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.commons.collections.ListUtils;

import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class DaoMuActivityMgr extends TempMgr {

    //活动配置
    static Map<Integer, DaoMuActivityConfig> activityConfigMap = new ConcurrentHashMap<>();
    private static Map<Integer, Map<String, DaoMuProto.DaoMuActivityConfig.Builder>> activityConfigMsgMap = new ConcurrentHashMap<>();

    /**
     * 加载活动配置
     */
    public static void reloadActivityData() {
        getLogger().info("reload daomu Activity start");
        Map<Integer, DaoMuActivityConfig> currentActivityConfigMap = new ConcurrentHashMap<>();
        //盗墓笔记
        List<ActivityInfo> activityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.DaoMu.getValue());
        initActivityConfig(activityList, currentActivityConfigMap);
        //盗墓奇遇-特殊服
        List<ActivityInfo> specialActivityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.DaoMuSpecial.getValue());
        initActivityConfig(specialActivityList, currentActivityConfigMap);
        activityConfigMap = currentActivityConfigMap;
        synchronized (activityConfigMsgMap){
            activityConfigMsgMap.clear();
        }
        //同步在线玩家
        List<GamePlayer> gamePlayerList = GamePlayerMgr.getAllOnlinePlayer();
        for (GamePlayer gamePlayer : gamePlayerList) {
            gamePlayer.getModule(DaoMuActivityModule.class).syncConfig(DaoMuSyncConfigTypeEnum.SYNC_CONFIG_TYPE_ALL);
        }
        getLogger().info("reload daomu Activity end");
    }

    /**
     * 初始化活动配置
     * @param openActivityInfoList
     */
    private static void initActivityConfig(List<ActivityInfo> openActivityInfoList, Map<Integer, DaoMuActivityConfig> currentActivityConfigMap) {
        for (ActivityInfo activityInfo : openActivityInfoList) {
            int activityId = activityInfo.getActivityId();
            //活动配置信息
            List<Integer> activityIdList = new ArrayList<>();
            activityIdList.add(activityId);
            Map<String, ActivityConfig> configMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(activityId);
            //关卡配置
            Map<Integer, DaoMuMissionConfig> missionConfigMap = DaoMuActivityBusiness.getDaoMuMissionConfig(activityId);
            //NPC配置
            Map<Integer, DaoMuNpcConfig> npcConfigMap = DaoMuActivityBusiness.getDaoMuNpcConfig(activityId);
            //藏品配置
            Map<Integer, DaoMuCurioConfig> curioConfigMap = DaoMuActivityBusiness.getDaoMuCurioConfig(activityId);
            //等级配置
            Map<Integer, DaoMuPlayerLevelConfig> levelConfigMap = DaoMuActivityBusiness.getDaoMuPlayerLevelConfig(activityId);
            //技能配置
            Map<Integer, DaoMuSkillConfig> skillConfigMap = DaoMuActivityBusiness.getDaoMuSkillConfig(activityId);
            //开棺宝箱配置
            Map<Integer, DaoMuCrowbarBoxConfig> crowbarBoxConfig = DaoMuActivityBusiness.getDaoMuCrowbarBoxConfig(activityId);
            //开棺宝箱进度配置
            Map<Integer, DaoMuProgressConfig> progressConfig = DaoMuActivityBusiness.getDaoMuProgressConfig(activityId);
            //开棺宝箱进度配置
            Map<Integer, DaoMuCaptainConfig> captainConfig = DaoMuActivityBusiness.getDaoMuCaptainConfig(activityId);
            //PVP配置
            Map<Integer, DaoMuPvpConfig> pvpConfig = DaoMuActivityBusiness.getDaoMuPvpConfig(activityId);
            // pvp技能配置
            Map<Integer, DaoMuPvpSkillConfig> pvpSkillConfig = DaoMuActivityBusiness.getDaoMuPvpSkillConfig(activityId);
            // pvp榜单配置
            Map<Integer, DaoMuPvpRankConfig> pvpRankConfig = DaoMuActivityBusiness.getDaoMuPvpRankConfig(activityId);

            //构造活动配置信息
            DaoMuActivityConfig daoMuActivityConfig = new DaoMuActivityConfig(activityInfo, configMap, missionConfigMap, npcConfigMap, curioConfigMap, levelConfigMap, skillConfigMap, crowbarBoxConfig, progressConfig, captainConfig, pvpConfig, pvpSkillConfig, pvpRankConfig);
            currentActivityConfigMap.put(activityId, daoMuActivityConfig);
        }
    }

    /**
     * 获取活动配置
     * @param activityId
     * @return
     */
    public static DaoMuActivityConfig getActivityConfig(int activityId) {
        return DaoMuActivityMgr.activityConfigMap.get(activityId);
    }

    /**
     * 获取活动配置MAP
     * @return
     */
    public static Map<Integer, DaoMuActivityConfig> getActivityConfigMap() {
        return DaoMuActivityMgr.activityConfigMap;
    }

    @Override
    public boolean init() throws Exception {
        return true;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    public static DaoMuProto.DaoMuActivityConfig.Builder getActivityConfigMsg(DaoMuActivityConfig daoMuActivityConfig, String language){
        if(null == daoMuActivityConfig){
            return DaoMuProto.DaoMuActivityConfig.newBuilder();
        }
        int activityId = daoMuActivityConfig.getActivityId();
        if(!activityConfigMsgMap.containsKey(activityId)){
            synchronized (activityConfigMsgMap){
                if(!activityConfigMsgMap.containsKey(activityId)){
                    activityConfigMsgMap.put(activityId, new ConcurrentHashMap<>());
                }
            }
        }
        Map<String, DaoMuProto.DaoMuActivityConfig.Builder> msgMap = activityConfigMsgMap.get(activityId);
        if(!msgMap.containsKey(language)){
            synchronized (msgMap){
                if(!msgMap.containsKey(language)){
                    DaoMuProto.DaoMuActivityConfig.Builder configMsg = DaoMuActivityPb.syncConfig(daoMuActivityConfig, language);
                    msgMap.put(language, configMsg);
                }
            }
        }
        return msgMap.get(language);
    }

//    /*********************************************pve局内相关******************************************************/
//
//    /**
//     * 盗墓笔记-前往探索
//     * @param playerId
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveExploreRespMsg pveExplore(long playerId, DaoMuProto.DaoMuPveExploreRespMsg.Builder msg) {
//        //获取活动
//        DaoMuActivityConfig activityConfig = activityConfigMap.get(msg.getPlayerInfo().getActivityId());
//        if (activityConfig == null) {
//            msg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return msg.build();
//        }
//        synchronized (activityConfig) {
//            //创建房间
//            DaoMuActivityPveRoom daoMuActivityRoom = createRoomDaoMu(playerId, activityConfig, msg);
//            //返回PB
//            msg.setRet(0);
//            msg.setRoomId(daoMuActivityRoom.getRoomId());
//            msg.setRoomPlayer(DaoMuActivityPb.createPveRoomPlayerPb(daoMuActivityRoom));
//            //开局给的道具
//            for (DaoMuBattlePropItem daoMuBattlePropItem : daoMuActivityRoom.getBattlePropMap().values()) {
//                DaoMuProto.DaoMuBattlePropItem stoneItem = DaoMuActivityPb.createDaoMuBattlePropItem(daoMuBattlePropItem);
//                msg.addBattlePropList(stoneItem);
//            }
//            return msg.build();
//        }
//    }
//
//    /**
//     * 盗墓奇遇-前往探索
//     * @param playerId
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveExploreRespMsg.Builder pveExploreSpecial(long playerId, int passesId, DaoMuActivityConfig activityConfig) {
//        DaoMuProto.DaoMuPveExploreRespMsg.Builder respMsg = DaoMuProto.DaoMuPveExploreRespMsg.newBuilder();
//        //创建房间
//        DaoMuActivityPveRoom daoMuActivityRoom = createRoomDaoMuSpecial(playerId, passesId, activityConfig);
//        //返回PB
//        respMsg.setRet(0);
//        respMsg.setRoomId(daoMuActivityRoom.getRoomId());
//        respMsg.setRoomPlayer(DaoMuActivityPb.createPveRoomPlayerPb(daoMuActivityRoom));
//        //开局给的道具
//        for (DaoMuBattlePropItem daoMuBattlePropItem : daoMuActivityRoom.getBattlePropMap().values()) {
//            DaoMuProto.DaoMuBattlePropItem stoneItem = DaoMuActivityPb.createDaoMuBattlePropItem(daoMuBattlePropItem);
//            respMsg.addBattlePropList(stoneItem);
//        }
//        return respMsg;
//    }

//    /**
//     * 创建房间-盗墓笔记
//     * @param activityConfig
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuActivityPveRoom createRoomDaoMu(long playerId, DaoMuActivityConfig activityConfig, DaoMuProto.DaoMuPveExploreRespMsg.Builder reqMsg) {
//        //关卡ID
//        int passesId = reqMsg.getBattleData().getPassesId();
//        //默认技能
//        DaoMuSkill defaultSkill = DaoMuActivityPb.parSkillInfo(reqMsg.getBattleData().getDefaultSkill());
//        //技能池子
//        Map<Integer, DaoMuSkill> skillMap = new HashMap<>();
//        for (DaoMuProto.DaoMuSkillItem skillItem : reqMsg.getBattleData().getSkillListList()) {
//            DaoMuSkill daoMuSkill = DaoMuActivityPb.parSkillInfo(skillItem);
//            skillMap.put(daoMuSkill.getSkillId(), daoMuSkill);
//        }
//        //技能最大等级MAP
//        Map<Integer, Integer> skillLevelMap = new HashMap<>();
//        for (DaoMuProto.DaoMuSkillItem skillItem : reqMsg.getBattleData().getSkillMaxLevelListList()) {
//            skillLevelMap.put(skillItem.getId(), skillItem.getLevel());
//        }
//        //属性MAP
//        Map<Integer, DaoMuAttribute> attributeMap = new HashMap<>();
//        for (DaoMuProto.DaoMuBattleAttribute attribute : reqMsg.getBattleData().getBattleAttributeListList()) {
//            DaoMuAttribute daoMuAttribute = DaoMuActivityPb.parAttribute(attribute);
//            attributeMap.put(daoMuAttribute.getId(), daoMuAttribute);
//        }
//        return createRoom(playerId, activityConfig, passesId, skillMap, defaultSkill, attributeMap, skillLevelMap);
//    }
//
//    /**
//     * 创建房间-盗墓奇遇
//     * @param playerId
//     * @param passesId
//     * @param activityConfig
//     * @return
//     */
//    public static DaoMuActivityPveRoom createRoomDaoMuSpecial(long playerId, int passesId, DaoMuActivityConfig activityConfig) {
//        //关卡配置
//        DaoMuMissionConfig muMissionConfig = activityConfig.getDaoMuMissionConfigMap().get(passesId);
//        //todo：校验
//        //获取角色默认技能
//        int roleId = muMissionConfig.getPartnerId();
//        DaoMuSkill defaultSkill = getRoleDefaultSkill(roleId, activityConfig);
//        //获取技能池
//        Map<Integer, DaoMuSkill> skillMap = muMissionConfig.getSpecialSkillMap();
//        if (!skillMap.containsKey(defaultSkill.getSkillId())) {
//            skillMap.put(defaultSkill.getSkillId(), defaultSkill);
//        }
//        //技能最高等级关系MAP
//        Map<Integer, Integer> skillLevelMap = muMissionConfig.getSpecialSkillLevelMap();
//        if (!skillLevelMap.containsKey(defaultSkill.getSkillId())) {
//            skillLevelMap.put(defaultSkill.getSkillId(), 5);
//        }
//        //获取属性MAP
//        String attributeStr = muMissionConfig.getParam();
//        Map<Integer, DaoMuAttribute> attributeMap = activityConfig.buildAttributeMap(attributeStr);
//        return createRoom(playerId, activityConfig, passesId, skillMap, defaultSkill, attributeMap, skillLevelMap);
//    }

//    /**
//     * 获取角色默认技能
//     * @param roleId 角色ID
//     * @return
//     */
//    public static DaoMuSkill getRoleDefaultSkill(int roleId, DaoMuActivityConfig activityConfig) {
//        Map<Integer, Integer> roleCollectionMap = getRoleMap();
//        int curioUnId = roleCollectionMap.get(roleId);
//        //藏品配置
//        DaoMuCurioConfig daoMuCurioConfig = activityConfig.getDaoMuCurioConfigMap().get(curioUnId);
//        int skillUnId = Integer.valueOf(daoMuCurioConfig.getUnlockSkillLevel());
//        //技能信息
//        DaoMuSkillConfig daoMuSkillConfig = activityConfig.getDaoMuSkillConfigMap().get(skillUnId);
//        DaoMuSkill daoMuSkill = new DaoMuSkill();
//        daoMuSkill.setSkillId(daoMuSkillConfig.getSkillId());
//        daoMuSkill.setSkillLevel(daoMuSkillConfig.getLevel());
//        daoMuSkill.setCollectionId(daoMuCurioConfig.getCurioId());
//        return daoMuSkill;
//    }

//    /**
//     * 获取角色MAP
//     * @return Map<Integer, Integer> k:角色ID,V:默认藏品ID
//     */
//    public static Map<Integer, Integer> getRoleMap() {
//        Map<Integer, Integer> map = new HashMap<>();
//        Map<Integer, GoodsInfo> goodsMap = GoodsMgr.getGoodsMapByType(eGoodsType.DaoMuRole.getValue());
//        for (GoodsInfo goodsInfo : goodsMap.values()) {
//            map.put(goodsInfo.getGoodsId(), goodsInfo.getParamList().get(0).intValue());
//        }
//        return map;
//    }

//    /**
//     * 创建房间
//     * @param playerId
//     * @param activityConfig
//     * @param passesId
//     * @param skillMap
//     * @param defaultSkill
//     * @param attributeMap
//     * @param skillLevelMap
//     * @return
//     */
//    public static DaoMuActivityPveRoom createRoom(long playerId, DaoMuActivityConfig activityConfig, int passesId,  Map<Integer, DaoMuSkill> skillMap, DaoMuSkill defaultSkill, Map<Integer, DaoMuAttribute> attributeMap,  Map<Integer, Integer> skillLevelMap) {
//        DaoMuActivityPveRoom room = new DaoMuActivityPveRoom(activityConfig, passesId, skillMap, defaultSkill, attributeMap, skillLevelMap);
//        //存储房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(activityConfig.getActivityId());
//        if (roomMap == null) {
//            roomMap = new ConcurrentHashMap<>();
//            activityRoomMap.put(activityConfig.getActivityId(), roomMap);
//        }
//        roomMap.put(playerId, room);
//        return room;
//    }



//    /**
//     * PVE-刷新NPC
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveRefreshNpcRespMsg.Builder pveRefreshNpc(long playerId, DaoMuProto.DaoMuPveRefreshNpcReqMsg reqMsg) {
//        DaoMuProto.DaoMuPveRefreshNpcRespMsg.Builder respMsg = DaoMuProto.DaoMuPveRefreshNpcRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            try {
//                //创建NPC
//                DaoMuCreateNpcRes daoMuCreateNpc = room.createNpc(reqMsg.getSecond());
//                //返回PB
//                return DaoMuActivityPb.createPveRefreshNpcRespMsgPb(daoMuCreateNpc);
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-普通NPC伤害上报
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveKillNpcRespMsg.Builder pveKillNpc(long playerId, DaoMuProto.DaoMuPveKillNpcReqMsq reqMsg) {
//        DaoMuProto.DaoMuPveKillNpcRespMsg.Builder respMsg = DaoMuProto.DaoMuPveKillNpcRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            //普通NPC伤害上报
//            room.attNpc(reqMsg.getAttNpcListList());
//            respMsg.setRet(0);
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-升级校验
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveUpgradeRespMsg.Builder pveUpgrade(long playerId, DaoMuProto.DaoMuPveUpgradeReqMsg reqMsg) {
//        DaoMuProto.DaoMuPveUpgradeRespMsg.Builder respMsg = DaoMuProto.DaoMuPveUpgradeRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            //升级校验
//            List<DaoMuSkill> selectSkillList = room.upgrade(reqMsg.getExp(), reqMsg.getExpStoneListList(), reqMsg.getMillisecond());
//            //返回PB
//            respMsg.setRoomPlayer(DaoMuActivityPb.createPveRoomPlayerPb(room));
//            if (selectSkillList != null) {
//                for (DaoMuSkill daoMuSkill : selectSkillList) {
//                    DaoMuProto.DaoMuSkillItem skillItem = DaoMuActivityPb.createDaoMuSkillItem(daoMuSkill);
//                    respMsg.addSkillList(skillItem);
//                }
//            }
//            respMsg.setRet(0);
//            System.out.println("技能选择list" + selectSkillList);
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-升级选择技能
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveUpgradeSelectSkillRespMsg.Builder pveUpgradeSelectSkill(long playerId, DaoMuProto.DaoMuPveUpgradeSelectSkillReqMsg reqMsg) {
//        DaoMuProto.DaoMuPveUpgradeSelectSkillRespMsg.Builder respMsg = DaoMuProto.DaoMuPveUpgradeSelectSkillRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            //选择技能
//            try {
//                room.upgradeSelectSkill(reqMsg.getSkillId(), reqMsg.getMillisecond());
//                //返回PB
//                respMsg.setRoomPlayer(DaoMuActivityPb.createPveRoomPlayerPb(room));
//                respMsg.setRet(0);
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * 获取PVE房间
//     * @param activityId
//     * @param playerId
//     * @return
//     */
//    public static DaoMuActivityPveRoom getPveRoom(int activityId, long playerId) {
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(activityId);
//        if (roomMap != null) {
//            return roomMap.get(playerId);
//        }
//        return null;
//    }
//
//    /**
//     * PVE-攻击上报（每秒上报【攻击BOSS】,【被攻击】伤害信息）
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveAttReportRespMsq.Builder pveAttReport(long playerId,  DaoMuProto.DaoMuPveAttReportReqMsq.Builder reqMsg) {
//        DaoMuProto.DaoMuPveAttReportRespMsq.Builder respMsg = DaoMuProto.DaoMuPveAttReportRespMsq.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            if (room.getDaoMuStatementInfo() != null) {
//                respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//                return respMsg;
//            }
//            //攻击上报
//            DaoMuAttReportRes result = room.attReport(reqMsg.getAttBossListList(), reqMsg.getBeAttListList());
//            //返回PB
//            respMsg.setRet(0);
//            respMsg.setRoomPlayer(DaoMuActivityPb.createPveRoomPlayerPb(room));
//            respMsg.setPassesId(room.getPassesId());
//            //boss数据
//            if (result.getBoss() != null) {
//                respMsg.setKillFlag(result.getBoss().getStatus() != DaoMuNpcStatusEnum.NPC_STATUS_EXIST.getStatus());
//                respMsg.setReduceHp(result.getBoss().getReHp());
//            }
//            //判断是否结算结算
//            if (room.getDaoMuStatementInfo() != null) {
//                //结算
//                DaoMuProto.DaoMuStatementInfoItem.Builder statementPb = DaoMuProto.DaoMuStatementInfoItem.newBuilder();
//                statementPb.setStatus(room.getDaoMuStatementInfo().isStatus());
//                statementPb.setKillNum(room.getDaoMuStatementInfo().getKillNum());
//                statementPb.setBattleTime(room.getDaoMuStatementInfo().getBattleTime());
//                statementPb.setPassesId(room.getPassesId());
//                statementPb.setOfferNpcIds(StringUtils.setToString(room.getOfferRewardNpcIdSet(), ";"));
//                statementPb.setLevel(room.getLevel());
//                statementPb.setSkillIds(room.getSkillIds());
//                reqMsg.setStatement(statementPb);
//                respMsg.setOverFlag(true);
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-打破瓦罐
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveBreakClayRespMsg.Builder pveBreakClay(long playerId, DaoMuProto.DaoMuPveBreakClayReqMsg reqMsg) {
//        DaoMuProto.DaoMuPveBreakClayRespMsg.Builder respMsg = DaoMuProto.DaoMuPveBreakClayRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            //打破瓦罐
//            try {
//                Map<Integer, DaoMuBattlePropItem> propItemMap = room.breakClay(reqMsg.getBattlePropId());
//                //返回PB
//                respMsg.setRet(0);
//                for (DaoMuBattlePropItem daoMuBattlePropItem : propItemMap.values()) {
//                    respMsg.addBattlePropList(DaoMuActivityPb.createDaoMuBattlePropItem(daoMuBattlePropItem));
//                }
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-捡道具
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPvePickUpPropRespMsg.Builder pvePickUpProp(long playerId, DaoMuProto.DaoMuPvePickUpPropReqMsg reqMsg) {
//        DaoMuProto.DaoMuPvePickUpPropRespMsg.Builder respMsg = DaoMuProto.DaoMuPvePickUpPropRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            //捡道具
//            try {
//                //捡起道具
//                room.pickUpProp(reqMsg.getBattlePropId());
//                //返回PB
//                respMsg.setRoomPlayer(DaoMuActivityPb.createPveRoomPlayerPb(room));
//                respMsg.setRet(0);
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-捡取宝箱
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPvePickUpBoxRespMsg.Builder pvePickUpBox(long playerId, DaoMuProto.DaoMuPvePickUpBoxReqMsg reqMsg) {
//        DaoMuProto.DaoMuPvePickUpBoxRespMsg.Builder respMsg = DaoMuProto.DaoMuPvePickUpBoxRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            try {
//                //捡起宝箱
//                DaoMuOpenBoxRes daoMuOpenBoxRes = room.pickUpBox(reqMsg.getBattlePropId(), reqMsg.getMillisecond());
//                //返回PB
//                respMsg.setRet(0);
//                respMsg.setRoomPlayer(DaoMuActivityPb.createPveRoomPlayerPb(room));
//                for (DaoMuSkill daoMuSkill : daoMuOpenBoxRes.getAllSkillList()) {
//                    respMsg.addSkillList(DaoMuActivityPb.createDaoMuSkillItem(daoMuSkill));
//                }
//                for (DaoMuSkill daoMuSkill : daoMuOpenBoxRes.getSelectedSkillList()) {
//                    respMsg.addSelectedSkillList(DaoMuActivityPb.createDaoMuSkillItem(daoMuSkill));
//                }
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-生成陶罐
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuCreateClayRespMsg.Builder pveCreateClay(long playerId, DaoMuProto.DaoMuCreateClayReqMsg reqMsg) {
//        DaoMuProto.DaoMuCreateClayRespMsg.Builder respMsg = DaoMuProto.DaoMuCreateClayRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (room) {
//            //生成陶罐
//            for (String position : reqMsg.getPositionList()) {
//                int battlePropId = room.createClay(position);
//                if (battlePropId > 0) {
//                    DaoMuProto.DaoMuClayItem.Builder clayItem = DaoMuProto.DaoMuClayItem.newBuilder();
//                    clayItem.setBattlePropId(battlePropId);
//                    clayItem.setPosition(position);
//                    respMsg.addClayItem(clayItem);
//                }
//            }
//            //返回PB
//            respMsg.setRet(0);
//            return respMsg;
//        }
//    }
//
//    /**
//     * 销毁房间
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuDestroyRoomRespMsg.Builder pveDestroyRoom(long playerId, DaoMuProto.DaoMuDestroyRoomReqMsg.Builder reqMsg) {
//        DaoMuProto.DaoMuDestroyRoomRespMsg.Builder respMsg = DaoMuProto.DaoMuDestroyRoomRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取房间
//        Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//        if (roomMap == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        DaoMuActivityPveRoom room = roomMap.get(playerId);
//        if (room == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PVE_ROOM_NOT_EXIST);
//            return respMsg;
//        }
//        //结算
//        DaoMuProto.DaoMuStatementInfoItem.Builder statementPb = DaoMuProto.DaoMuStatementInfoItem.newBuilder();
//        statementPb.setStatus(false);
//        statementPb.setKillNum(room.countKillNpcNum());
//        statementPb.setBattleTime(room.countBattleTime());
//        statementPb.setPassesId(room.getPassesId());
//        statementPb.setOfferNpcIds(StringUtils.setToString(room.getOfferRewardNpcIdSet(), ";"));
//        statementPb.setLevel(room.getLevel());
//        statementPb.setSkillIds(room.getSkillIds());
//        reqMsg.setStatement(statementPb);
//        reqMsg.setActivityId(daoMuActivity.getActivityId());
//        //清除房间
//        roomMap.remove(playerId);
//        return respMsg;
//    }
//
//    /**
//     * 结算增加奖励
//     * @param player
//     * @param reqMsg
//     */
//    public static void pveStatement(GamePlayer player, DaoMuProto.DaoMuPveAttReportRespMsq reqMsg) {
//        //获取活动
//        DaoMuActivityConfig daoMuActivity = activityConfigMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            return;
//        }
//        synchronized (daoMuActivity) {
//            //获取房间
//            Map<Long, DaoMuActivityPveRoom> roomMap = activityRoomMap.get(reqMsg.getActivityId());
//            if (roomMap == null) {
//               return;
//            }
//            DaoMuActivityPveRoom room = roomMap.get(player.getUserId());
//            if (room == null) {
//                return;
//            }
//            //结算
//            if (reqMsg.getOverFlag()) {
//                //首通奖励
//                if (!StringUtils.isNullOrEmpty(reqMsg.getStatement().getReward())) {
//                    player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(reqMsg.getStatement().getReward()), eLogMoneyType.DaoMu, eLogMoneyType.DaoMuPassPassesReward);
//                }
//                //悬赏奖励
//                if (!StringUtils.isNullOrEmpty(reqMsg.getStatement().getOfferReward())) {
//                    player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(reqMsg.getStatement().getOfferReward()), eLogMoneyType.DaoMu, eLogMoneyType.DaoMuReceiveOfferReward);
//                }
//                //血脉道具
//                Property property = new Property();
//                property.setGood(GameConfig.DAOMU_ACTIVITY_ZQL_XM_PROP_ID, BigInteger.valueOf(reqMsg.getStatement().getKillNum()));
//                player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.DaoMu, eLogMoneyType.DaoMuZqlXmPropAdd);
//                //是否过关
//                if (reqMsg.getStatement().getStatus()) {
//                    //判断关卡是否是历史最高，如果是存储
//                    long maxPassesId = player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.DaoMuMaxPassesId);
//                    if (reqMsg.getPassesId() > maxPassesId) {
//                        player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.DaoMuMaxPassesId, reqMsg.getPassesId());
//                    }
//                }
//                //清除房间
//                roomMap.remove(player.getUserId());
//            }
//        }
//    }

}
